import {
  baseImgUrl,
  // 市场动态
  getMarketListApi,
  // 行业资讯【热点】精选资讯
  getIndustryInfoConNewsListApi,
  // 获取涉农信息分类的接口
  getAgriculInformationTypeApi
} from "../apis/api";
// 获取市场动态的服务
export const baseHttpMarketServiceMarket = {
  data() {
    return{
      // 市场动态数据
      marketListData: null,
      // 总条数
      marketListTotal: 0
    }
  },
  methods: {
    // 市场动态的数据   [后期待抽离公共函数]
    getMarketListData(params) {
      const that = this;
      let p = {};
      p.minTime = params && params.time.minTime ? params.time.minTime : '';
      p.maxTime = params && params.time.maxTime ? params.time.maxTime : '';
      p.title = params && params.title ? params.title : '';
      p.page = params && params.page ? params.page : 1;
      p.rows = params && params.rows ? params.rows : 6;
      getMarketListApi(p).then(res => {
        //console.log('这是市场动态的数据');
        that.marketListData = res.data;
        that.marketListTotal = res.count
      })
    },
  }
};
// 获取行业资讯的服务
export const baseHttpIndustryInfoService = {
  data() {
    return{
      // 市场动态数据
      industryInfoListData: null,
      // 总条数
      industryInfoListTotal: 0
    }
  },
  methods: {
    // 市场动态的数据   [后期待抽离公共函数]
    getMarketListData(params) {
      const that = this;
      let p = {};
      p.minTime = params && params.minTime ? params.minTime : '';
      p.maxTime = params && params.maxTime ? params.maxTime : '';
      p.title = params && params.title ? params.title : '';
      p.page = params && params.page ? params.page : 1;
      p.rows = params && params.rows ? params.rows : 12;
      // 是否热点
      p.hot = params && params.hot ? 1 : '';
      p.type = params && params.type ? params.type : '';
      getIndustryInfoConNewsListApi(p).then(res => {
        //console.log('这是市场动态的数据');
        that.industryInfoListData = res.data;
        that.industryInfoListTotal = res.count
      })
    },
  }
};
// 获取涉农信息的分类的服务
export const getAgriculInformationTypeService = {
  data() {
    return{
      // tab栏是否有蓝色的的class
      currentHasTabStyle: "",
      tabArrList: [],
      // 当前的
      curentType: {
        name:'',
        id:''
      },
      sssss :''
    }
  },
  methods: {
    // 涉农信息的分类列表  [后期待抽离公共函数]
    getAgriculInformationTypeData(params) {
      const that = this;
      let  ps =[]
      getAgriculInformationTypeApi().then(res => {
        res.forEach((item) => {
          let p = {name: item.sort_name,type:item.id};
          ps.push(p)
        })
        that.currentHasTabStyle = that.tabArrList[0].name;
        that.curentType.name = that.currentHasTabStyle;
        that.curentType.id = res[0].id;
        that.sssss = res[0].id;
        // 获取信息
        const item = {
          type: that.curentType.id,
          limit: 5,
          search: that.keyWord,
          page: 1
        };
        //console.log(item)
        that.gatDataByObj(item);
      })
      that.tabArrList = ps;

    },
  }
};
